package com.amc.websocket;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;


@Controller("OrderHandler")
public class OrderRefresh extends TextWebSocketHandler{
private Map<String,WebSocketSession> sessions = new HashMap<String,WebSocketSession>();
	
	
	
	@Override
	public void handleTextMessage(WebSocketSession session, TextMessage message) {
		// 接收到客户端消息时调用
		System.out.println("text message: " + session.getId() + "-"
				+ message.getPayload());
	}

	@Override
	public void afterConnectionEstablished(WebSocketSession session)
			throws Exception {
		// 与客户端完成连接后调用
		//HttpSession httpSess =(HttpSession)session.getAttributes().get(HttpSession.class.getName());
		System.out.println(this);
		session.sendMessage(new  TextMessage("Hello browser"));
	}

	@Override
	public void handleTransportError(WebSocketSession session,
			Throwable exception) throws Exception {
		// 消息传输出错时调用
		System.out.println("handleTransportError");
	}

	@Override
	public void afterConnectionClosed(WebSocketSession session,
			CloseStatus closeStatus) throws Exception {
		// 一个客户端连接断开时关闭
		System.out.println("afterConnectionClosed");
	}

	@Override
	public boolean supportsPartialMessages() {
		// TODO Auto-generated method stub
		return false;
	}
}
